﻿Imports System.Collections.ObjectModel

Public Class PasswordForm
    Public Property Password As String
    Public Property User As String
    Public Property CreateProfile As Boolean = False

    Public Property Users As New ObservableCollection(Of String)

    Public Sub New(badPass As Boolean, users As IEnumerable(Of String))
        For Each item In users
            Me.Users.Add(item)
        Next

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call
        If badPass Then
            tbFirstTry.Visibility = Windows.Visibility.Collapsed
        Else
            tbBadPass.Visibility = Windows.Visibility.Collapsed
        End If
    End Sub

    Private Sub pBox_PasswordChanged(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Password = pBox.Password
    End Sub

    Private Sub ButtonCancel_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim pw = TryCast(Parent, Window)
        If pw IsNot Nothing Then
            pw.DialogResult = False
            pw.Close()
        End If
    End Sub

    Private Sub ButtonOK_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim pw = TryCast(Parent, Window)
        If pw IsNot Nothing Then
            pw.DialogResult = True
            pw.Close()
        End If
    End Sub

    Private Sub cbUser_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
        User = Users(cbUser.SelectedIndex)
    End Sub

    Private Sub buttonCreateProfile_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        CreateProfile = True
        Dim pw = TryCast(Parent, Window)
        If pw IsNot Nothing Then
            pw.DialogResult = False
            pw.Close()
        End If
    End Sub
End Class
